<!--
 * @Descripttion: 
 * @Author: voanit
 * @Date: 2022-08-24 08:36:49
 * @LastEditors: voanit
 * @LastEditTime: 2022-08-24 08:52:05
-->
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    /* 研究一个对象就是研究他的：属性+方法+回调函数 */
    /* var xmlhttp = new XMLHttpRequest();
    xmlhttp.open('GET', 'https://api-hmugo-web.itheima.net/api/public/v1/home/swiperdata', true);
    xmlhttp.send();
    xmlhttp.onload = function (res) {
      //  成功后执行
      console.log(JSON.parse(xmlhttp.responseText), 12111);
    } */

    function axios (url, method = 'get') {
      return new Promise((resolve, reject) => {
        var xmlhttp = new XMLHttpRequest();
        xmlhttp.open(method, url, true);
        xmlhttp.send();
        xmlhttp.onload = function (res) {
          //  成功后执行
          // console.log(JSON.parse(xmlhttp.responseText), 12111);
          resolve(JSON.parse(xmlhttp.responseText))
        }
      })
    }
    axios('https://api-hmugo-web.itheima.net/api/public/v1/home/swiperdata').then((res) => {
      console.log(res, 999);
    })

  </script>
</body>

</html>